<?php
defined('IN_PHPCMS') or exit('No permission resources.');
class index {
    private $db;
	private $db1;
	function __construct() {
	$this->db = pc_base::load_model('foodmanu_model');
	$this-db1= pc_base::load_model('foodmanu_data_model');
	}
	
	public function init() {
	$result = $this->db->select();
	/* 模糊查询 */
	$name = isset($_POST['name']) ? mysql_real_escape_string($_POST['name']) : ''; 
    $author = isset($_POST['author']) ? mysql_real_escape_string($_POST['author']) : '';	
$cx = isset($_POST['cx']) ? mysql_real_escape_string($_POST['cx']) : '';
	$cj = isset($_POST['cj']) ? mysql_real_escape_string($_POST['cj']) : '';
	$bz = isset($_POST['bz']) ? mysql_real_escape_string($_POST['bz']) : '';
	$gw= isset($_POST['gw']) ? mysql_real_escape_string($_POST['gw']) : '';
$uid = isset($_POST['uid']) ? mysql_real_escape_string($_POST['uid']) : '';
$date = isset($_POST['date']) ? mysql_real_escape_string($_POST['date']) : '';
	$sql="name like '%$name%' and author like '%$author%' and gw like '%$gw%' and date like '%$date%' and bz like '%$bz%' and cj like '%$cj%' and uid like '%$uid%' and cx like '%$cx%'";
	/* 模糊查询 */
		$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
$pagesize = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
	    $count=$this->db->count($sql, '`id` DESC', $page);
		$data = $this->db->listinfo($sql, '`id` DESC', $page,$pagesize);


$result["total"]  = $count;		
$result["rows"] = $data ;
echo json_encode($result);

	}
/* 添加 */
	public function add(){
	
	$data['name']= isset($_POST['name']) ? mysql_real_escape_string($_POST['name']) : ''; 
	$data['cj'] = isset($_POST['cj']) ? mysql_real_escape_string($_POST['cj']) : '';
	$data['bz'] = isset($_POST['bz']) ? mysql_real_escape_string($_POST['bz']) : '';
	$data['gw'] = isset($_POST['gw']) ? mysql_real_escape_string($_POST['gw']) : '';
	
	$data['cx'] = isset($_POST['cx']) ? mysql_real_escape_string($_POST['cx']) : '';
    $data['author'] = isset($_POST['author']) ? mysql_real_escape_string($_POST['author']) : '';
	$data['uid'] = isset($_POST['uid']) ? mysql_real_escape_string($_POST['uid']) : '';//指导书编号
	$data['date'] = isset($_POST['creatdate']) ? mysql_real_escape_string($_POST['creatdate']) : '';
	$data['url'] = isset($_POST['urltext']) ? mysql_real_escape_string($_POST['urltext']) : '';
    $data['userid'] = param::get_cookie('_userid');//操作员id
	
	$result = $this->db->insert($data);

	 if($result)
echo $message."添加成功";	
else
	echo $message.'失败，错误报告是:'.mysql_error();
	}
/* 添加 end */
/* 删除 */	
public function dele(){
        //获得userid
        $_userid= param::get_cookie('_userid');
		
		$id=$_POST['id'];
		$userid=$_POST['userid'];

$sql="id like ".$id;
$url = $this->db->get_one($sql,'url');//合计
$file=$url['url'];//合计
if($file){
$filePath = 'uploadfile/zpgy/';  
$uploadfile=$filePath.$file;
unlink(iconv("UTF-8","gb2312",$uploadfile));
}

$where="`id`='$id'";
if($userid==$_userid)
{$result = $this->db->delete($where);
	
	    if($result)
echo $message."删除成功";	
else
	echo $message.'失败，错误报告是:'.mysql_error();

}
else
{
echo $message.'您没有上传此作业指导书文件，无法删除';
}
	
}
/* 删除 end*/		
public function edit(){	
		$id=$_GET['id'];
		
$where="`id`='$id'";

	$data['name']= isset($_POST['name']) ? mysql_real_escape_string($_POST['name']) : ''; 
	$data['cj'] = isset($_POST['cj']) ? mysql_real_escape_string($_POST['cj']) : '';
	$data['bz'] = isset($_POST['bz']) ? mysql_real_escape_string($_POST['bz']) : '';
	$data['gw'] = isset($_POST['gw']) ? mysql_real_escape_string($_POST['gw']) : '';
	$data['cx'] = isset($_POST['cx']) ? mysql_real_escape_string($_POST['cx']) : '';
    $data['author'] = isset($_POST['author']) ? mysql_real_escape_string($_POST['author']) : '';
	$data['uid'] = isset($_POST['uid']) ? mysql_real_escape_string($_POST['uid']) : '';//指导书编号
	$data['date'] = isset($_POST['date']) ? mysql_real_escape_string($_POST['date']) : '';
/* $url = isset($_POST['urltext']) ? mysql_real_escape_string($_POST['urltext']) : ''; */
	
	$result = $this->db->update($data,$where);
		    if($result)
echo $message."编辑成功";	
else
	echo $message.'失败，错误报告是:'.mysql_error();   
}

public function url(){	



$name=$_GET['name'];;
/* $fl=$_GET['fl'];

if($fl=='1'){

include template('zpgy','url','default');

}
if($fl=='0')
{
include template('zpgy','spurl','default');

} */
include template('zpzyzds','url','default');

}



public function count(){
$_nickname = param::get_cookie('_nickname');
if($_nickname==''){
$_nickname='游客';}

$result = $this->db->count();
$sql="";
$data["total"]  = $this->db->select($sql,'count(*) total','','','left(date,7)','');//合计
$data['date'] = $this->db->select($sql,'date','','','left(date,7)','');//合计
$people = $this->db->select($sql,'author,count(*) total','','','author','');//合计

for($i=0;$i<count($data["date"]);$i++){
		$data["date"][$i]['date']=substr($data["date"][$i]['date'],0,7).'月';
	}
//echo '<h4>﻿目前上传装配工艺'.$result1.'份，视频工艺'.$result2.'份。</h4>';
include template('zpzyzds','zpzyzds_index','default');
}


public function zpzyzds(){
$_groupid = param::get_cookie('_groupid');
$_userid= param::get_cookie('_userid');
if (empty($_groupid))
{
$_groupid='999999';
}if (empty($_userid))
{
$_userid='999999';
}
include template('zpzyzds','zpzyzds','default');

}
/* public function spgy(){
$_groupid = param::get_cookie('_groupid');
$_userid= param::get_cookie('_userid');
if (empty($_groupid))
{
$_groupid='999999';
}if (empty($_userid))
{
$_userid='999999';
}
include template('zpgy','spgy','default');

} */

public function exportt(){
include template('project','download','default');
}
}	

?>